package org.ala.tcp_feign_common.msg.close;

import org.ala.tcp_feign_common.enums.TcpFeignCloseTypeEnums;
import org.ala.tcp_feign_common.enums.TcpFeignMessageTypeEnums;
import org.ala.tcp_feign_common.msg.AbstractByteMessage;


/**
 * 断连消息
 * 
 * [0x09 | 消息体总长（4子节）| 断开连接时间戳（8字节）| 断连原因（4字节）]
 * 
 * @author 骆毅(ala)
 * @date 2024年4月19日
 */
public class CloseByteMessage extends AbstractByteMessage {
	private static final long serialVersionUID = 1L;

	
	/**
	 * 断连消息时间戳
	 */
	protected long timestamp;
	/**
	 * 断连原因错误码
	 */
	protected TcpFeignCloseTypeEnums code;
	
	
	public static CloseByteMessage build(TcpFeignCloseTypeEnums code) {
		CloseByteMessage msg = new CloseByteMessage();
		msg.setTimestamp(System.currentTimeMillis());
		msg.setCode(code);
		return msg;
	}
	
	
	@Override
	public TcpFeignMessageTypeEnums type() {
		return TcpFeignMessageTypeEnums.CLOSE;
	}


	public long getTimestamp() {
		return timestamp;
	}


	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}


	public TcpFeignCloseTypeEnums getCode() {
		return code;
	}


	public void setCode(TcpFeignCloseTypeEnums code) {
		this.code = code;
	}

}
